<template>
  <QupFormContainer :column="3">
    <el-form ref="form" :model="formData" :rules="formRules" label-width="110px">
      <el-form-item prop="reviewResult" label="审批结果">
        <c-dict-select v-model="formData.reviewResult" dict-type-code="REVIEW_RESULT" clearable placeholder="审批结果" />
      </el-form-item>
      <el-form-item prop="reviewAdvice" label="审批意见" :span="24">
        <el-input v-model="formData.reviewAdvice" type="textarea" show-word-limit maxlength="1024" :autosize="{minRows: 3}" placeholder="审批意见" clearable />
      </el-form-item>
    </el-form>
  </QupFormContainer>
</template>
<script>
export default {
  name: 'AuditForm',
  props: {
  },
  data() {
    return {
      formData: {
        reviewResult: '',
        reviewAdvice: ''
      }
    }
  },
  computed: {
    formRules() {
      return {
        reviewResult: [{ required: true, message: '请选择审核结果', trigger: 'change' }],
        reviewAdvice: [{ required: ['0', 0].includes(this.formData.reviewResult), message: '请选择审核结果', trigger: 'change' }]
      }
    }
  },
  watch: {
    formData: {
      handler(v) {
        this.$emit('change', v)
      },
      immediate: true,
      deep: true
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.form && this.$refs.form.clearValidate()
    })
  },
  methods: {
    validate() {
      return this.$refs.form.validate().then(() => this.formData)
    }
  }
}
</script>
